/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ClassesJava;

import connexion.ConnectionManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author acer abdelfattah Rabou
 * ISMAYLOULABBIHI
 */
public class Matieres {
    
    
    public ConnectionManager c;
    private int numero ;
    private String label;
    private int nbr_heures ;
    
    public Matieres(int numero, String label, int nbr_heures){
    
       this.numero=numero;
       this.label=label;
       this.nbr_heures=nbr_heures;
    }
public Matieres() {
      //To change body of generated methods, choose Tools | Templates.

    }
 public int getNum() {
        return numero;
    }

    public void setNum(int numero) {
        this.numero = numero;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public int getNbr_heures() {
        return nbr_heures;
    }

    public void setNbr_heures(int nbr_heures) {
        this.nbr_heures = nbr_heures;
    }


    //ajouter data

    public int ajouter(Matieres m) {
        int i;
        c = new ConnectionManager();
        String rq = "INSERT INTO  `gestion_des_emplois`.`matiere` (idM , label ,NbHeurs )"
                + " VALUES (NULL ,'" + m.getLabel() + "', '" + m.getNbr_heures() + "')";
        i = c.setDataBase(rq);
        return i;
    }
   //Modifier data

    public int modifier(Matieres m) {
        int i = 0;
        c = new ConnectionManager();
        String rq = "UPDATE  `gestion_des_emplois`.`matiere` SET `label` = '" + m.getLabel() + "', "
                + "`NbHeurs` = '" + m.getNbr_heures() + "' where idM=" + m.getNum();
        i = c.setDataBase(rq);
        return i;
    }
   //supprimer data

    public int supprimer(Matieres m) {
        int i = 0;
        c = new ConnectionManager();
        String rq = "DELETE FROM `gestion_des_emplois`.`matiere` where idM=" + m.getNum();
        i = c.setDataBase(rq);
        return i;
    }
 //afficher data

    public Vector<Matieres> getMatieres() {
        Vector<Matieres> res = new Vector();
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("select * from matiere");

            while (rs.next()) {
                Matieres m = new Matieres(rs.getInt(1), rs.getString(2), rs.getInt(3));
                res.add(m);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Matieres.class.getName()).log(Level.SEVERE, null, ex);
        }

        return res;
    }
public Matieres  getMatiereByID(int id) {
    Matieres m = null;
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("select * from matiere WHERE idM="+id);

            while (rs.next()) {
                 m = new Matieres(rs.getInt(1), rs.getString(2), rs.getInt(3));                
            }

        } catch (SQLException ex) {
            Logger.getLogger(Matieres.class.getName()).log(Level.SEVERE, null, ex);
        }

        return m;
    }
}    

